<%-- 
    Document   : setValue
    Created on : 2013-6-9, 15:04:50
    作者     : $赵远
--%>

<%@page import="cn.com.jsepc.rep.setvalue.SetValueGrid"%>
<%@ page language="java" import="java.util.*,cn.com.jsepc.rep.report.*" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    String roleid = (String) session.getAttribute("midawa_UserRoles");
    String corpid = (String) session.getAttribute("midawa_Usercorps");
    if (roleid == null) {
        roleid = "100001";
    }
    if (corpid == null) {
        corpid = "32101";
    }
    String repid = request.getParameter("repid");
    if (repid == null) {
        repid = "218";
    }
    String openUrl;
    double r = Math.random();
    StringBuffer urlBuffer = new StringBuffer();
    urlBuffer.append(basePath);
    urlBuffer.append("JarpListener");
    urlBuffer.append("?className=cn.com.jsepc.rep.report.FillDataDAO");
    urlBuffer.append("&methodName=getFillGridCol");
    urlBuffer.append("&paramCount=4");
    urlBuffer.append("&param_0=" + repid + "&param_1=1&param_2=" + corpid + "&param_3=" + r);
    openUrl = urlBuffer.toString();
    String setValueGridDataUrl=basePath+"JarpListener?className=cn.com.jsepc.rep.setvalue.SetValueGrid&methodName=getDataGrid&paramCount=1&param_0=1";
    SetValueGrid setValue=new SetValueGrid();
    String res=setValue.getDataGrid(repid);
%>
<!DOCTYPE html>
<html>
    <head>
        <script>
            var basePath = '<%=basePath%>';
            var repid = '<%=repid%>';
            var corpid = '<%=corpid%>';
            var roleid = '<%=roleid%>';
        </script>
        
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>自动设定值</title>
        <link rel="stylesheet" type="text/css" href="../ext3/resources/css/ext-all.css">
        <link rel="stylesheet" type="text/css" href="css/grid-examples.css" />
        <script type="text/javascript" src="../ext3/adapter/ext/ext-base.js"></script>
        <script type="text/javascript" src="../ext3/ext-all.js"></script>
        <script type="text/javascript" src="../ext3/ext-lang-zh_CN.js"></script>
        <script type="text/javascript">
            Ext.BLANK_IMAGE_URL = '../ext3/resources/images/default/s.gif';
            Ext.SSL_SECURE_URL = '../ext3/resources/images/default/s.gif';
        </script>
        
        <script type="text/javascript" src="../js/TreeCheckNodeUI.js"></script>
        <script type="text/javascript" src="../js/ColumnNodeUI.js"></script>
        <script type="text/javascript" src="js/SessionProvider.js"></script>
        <script language="javascript" src="../js/XMLHttpRequest.js" type="text/javascript"></script>
        <script type="text/javascript" src=<%=openUrl%>></script>  
        <script type="text/javascript" >
            Ext.onReady(function(){
                <%=res%>
                var setValue = new Ext.FormPanel({
        id: 'setValue',
        labelWidth: 80,
        width: '98%',
        height: '100%',
        bodyStyle: 'padding: 4px',
        border: false,
        autoscroll: true,
        frame: true,
        autoScroll: true,
        items: [{
                title: '自动设定值',
                layout: 'form',
                autoscroll: true,
                xtype: 'fieldset',
                collapsible: true,
                collapsed: false,
                labelAlign: 'right',
                height: '100%',
                defaults: {
                    width: '100%'
                },
                items: [{
                        xtype: "textfield",
                        fieldLabel: "当期值",
                        emptyText: '当期值',
                        disabled: false,
                        //columnWidth: .3,
                        id: 'bianhao_repval',
                        anchor: "70%"
                    }, {
                        xtype: "textfield",
                        fieldLabel: "累计值",
                        emptyText: '累计值',
                        disabled: false,
                        //columnWidth: .3,
                        id: 'bianhao_sumval',
                        anchor: "70%"
                    }, {
                        xtype: "textfield",
                        fieldLabel: "同期值",
                        //columnWidth: .3,
                        emptyText: '同期值',
                        disabled: false,
                        id: 'bianhao_trepval',
                        anchor: "70%"
                    }, {
                        xtype: "textfield",
                        fieldLabel: "同期累积",
                        //columnWidth: .3,
                        emptyText: '同期累计值',
                        disabled: false,
                        id: 'bianhao_tsumval',
                        anchor: "70%"
                    }, {
                        xtype: "textfield",
                        fieldLabel: "上期值",
                        emptyText: '上期值',
                        disabled: false,
                        //columnWidth: .3,
                        id: 'bianhao_preval',
                        anchor: "70%"
                    }, {
                        xtype: "textfield",
                        fieldLabel: "上期累计",
                        //columnWidth: .3,
                        emptyText: '上期累计值',
                        disabled: false,
                        id: 'bianhao_tpreval',
                        anchor: "70%"
                    }, {
                        xtype: 'datefield',
                        fieldLabel: '开始时间',
                        name: 'starttime_date',
                        id: 'starttime_date',
                        altFormats: 'Ymd',
                        format: 'Y-m-d',
                        dateFormat: 'Ymd',
                        //columnWidth: .9,
                        emptyText: '任务开始时间',
                        anchor: "70%"
                    }, {
                        xtype: 'datefield',
                        fieldLabel: '结束时间',
                        name: 'endtime_date',
                        id: 'endtime_date',
                        altFormats: 'Ymd',
                        format: 'Y-m-d',
                        dateFormat: 'Ymd',
                        emptyText: '任务结束时间',
                        //columnWidth: .9,
                        anchor: "70%"
                    }]
            }]
    });
    /**
     * 
     * @type @exp;Ext@call;Window
     * 用于维度过滤
     */
    var shuju_win = new Ext.Window({
        id: 'shuju_win',
        title: "维度过滤(可不选时间维度)",
        border: false,
        bodyBorder: false,
        // layout:'fit',
        width: 435,
        // height:auto,
        closeAction: 'hide',
        modal: true,
        tbar: ['-', {
                text: ' 确定 ',
                handler: function() {
                    //进行数据操作
                    var repval = Ext.ComponentMgr.get("bianhao_repval").getValue();
                    var sumval = Ext.ComponentMgr.get("bianhao_sumval").getValue();
                    var preval = Ext.ComponentMgr.get("bianhao_preval").getValue();
                    var tpreval = Ext.ComponentMgr.get("bianhao_tpreval").getValue();
                    var trepval = Ext.ComponentMgr.get("bianhao_trepval").getValue();
                    var tsumval = Ext.ComponentMgr.get("bianhao_tsumval").getValue();
                    var start = dateFormat(Ext.ComponentMgr.get("starttime_date").getValue());
                    var end = dateFormat(Ext.ComponentMgr.get("endtime_date").getValue());
                    if (repval == "") {
                        Ext.MessageBox.alert("错误", "请输入当期值！");
                        return;
                    }
                    if (sumval == "") {
                        Ext.MessageBox.alert("错误", "请输入累计值！");
                        return;
                    }
                    if (preval == "") {
                        Ext.MessageBox.alert("错误", "请输入上期值！");
                        return;
                    }
                    if (tpreval == "") {
                        Ext.MessageBox.alert("错误", "请输入上期累计值！");
                        return;
                    }
                    if (trepval == "") {
                        Ext.MessageBox.alert("错误", "请输入同期值！");
                        return;
                    }
                    if (tsumval == "") {
                        Ext.MessageBox.alert("错误", "请输入同期累计值！");
                        return;
                    }
                    if (start == "") {
                        Ext.MessageBox.alert("错误", "请选择开始时间！");
                        return;
                    }
                    if (end == "") {
                        Ext.MessageBox.alert("错误", "请选择结束时间！");
                        return;
                    }

                    var dimColValue = getExportDemlist();
                    if (dimColValue == "") {
                        Ext.MessageBox.alert("错误", "请筛选维度！");
                        return "";
                    }
                    var openUrl = basePath
                            + 'JarpListener?className=cn.com.jsepc.rep.report.AutoSetValue';
                    openUrl += '&methodName=setValue&paramCount=11&param_0=' + repid + '&param_1=' + roleid + '&param_2=' + getExportDemlist() + '&param_3=' + repval
                            + '&param_4=' + sumval + '&param_5=' + preval + '&param_6=' + tpreval + '&param_7=' + trepval + '&param_8=' + tsumval + '&param_9=' + start + '&param_10=' + end;
                    httpR_itemInfo = getXMLHttpRequest();
                    httpR_itemInfo.onreadystatechange = returnSetValue;
                    httpR_itemInfo.open("POST", openUrl, true);
                    httpR_itemInfo.send();
                    function returnSetValue() {
                        if (httpR_itemInfo.readyState == 4) {
                            if (httpR_itemInfo.status == 200) {
                                ret = httpR_itemInfo.responseText;
                                alert(ret);
                                 store_setValues.reload();
                            }
                        }
                    }
                    shuju_win.hide();
                }
            }, '-', {
                text: ' 关闭 ',
                handler: function() {
                    shuju_win.hide();
                }
            }, '-'],
        items: [shuju_weidu, shuju_pal, setValue]
    });





    //主视图
    var viewport = new Ext.Viewport({
        layout: 'border',
        items: [{
                tbar: ['-', {
                        text: '添加任务',
                        iconCls: '',
                        handler: function() {
                            shuju_win.show();
                            shuju_win.doLayout();
                        }
                    }, '-', {
                        text: '删除任务',
                        handler: function() {
                            var re_grid = Ext.ComponentMgr.get("chc").getSelectionModel().getSelected();
                            if (re_grid) {
                                deleteFunction(re_grid.data.id);
                                store_setValues.reload();
                            } else {
                                Ext.Msg.alert('提示', '请选择任务!');
                            }
                        }
                    }, '-', {
                        text: '关闭窗口',
                        handler: function() {
                            window.close();
                        }
                    }, '-'
                ],
                region: 'center',
                deferredRender: false,
                activeTab: 0,
                frame: true,
                layout: 'border',
                items: [grid_logs]
            }]
    });

    function getExportDemlist() {
        var sender = {};
        var hideCol = [];
        var array = [];
        for (var i = 0; i < dimLen; i++) {
            var o = {};
            o.facdimtablewan = Ext.ComponentMgr.get("facdimtablewan" + i).getValue();
            o.facdimcodecolwan = Ext.ComponentMgr.get("facdimcodecolwan" + i).getValue();
            o.facdimvaluewan = Ext.ComponentMgr.get("facdimvaluewan" + i).getValue();
            o.facdimfieldwan = Ext.ComponentMgr.get("facdimfieldwan" + i).getValue();
            o.facdimtable_weidu = Ext.ComponentMgr.get("facdimtable_weidu" + i).getValue();
            o.facdimcodecol_weidu = Ext.ComponentMgr.get("facdimcodecol_weidu" + i).getValue();
            o.facdimvalue_weidu = Ext.ComponentMgr.get("facdimvalue_weidu" + i).getValue();
            //demArr[i]  = o;
            if (o.facdimvalue_weidu == "") {
                hideCol.push(o.facdimfield);
            }
            array.push(o);
        }
        if (dimLen == hideCol.length) {
            return "";
        }
        sender.demlist = array;
        // alert(Ext.util.JSON.encode(sender));
        return Ext.util.JSON.encode(sender);
    }

    /**
     * 
     * @param {type} value
     * @returns {@exp;Ext@pro;util@pro;Format@call;date}
     * 用来格式化时间
     */
    function dateFormat(value) {
        if (null != value && value != "") {
            return Ext.util.Format.date(new Date(value), 'Ymd');
        } else {
            return "";
        }
    }
    
    function deleteFunction(id){
         var openUrl = basePath + 'JarpListener?className=cn.com.jsepc.rep.setvalue.SetValueDAO';
                    openUrl += '&methodName=deleteFunction&paramCount=1&param_0=' + id ;
                    httpR_itemInfo = getXMLHttpRequest();
                    httpR_itemInfo.onreadystatechange = returnDeleteFunction;
                    httpR_itemInfo.open("POST", openUrl, true);
                    httpR_itemInfo.send();
                    function returnDeleteFunction() {
                        if (httpR_itemInfo.readyState == 4) {
                            if (httpR_itemInfo.status == 200) {
                                ret = httpR_itemInfo.responseText;
                                Ext.Msg.alert("提示",ret);
                            }
                        }
                    }
    }
            });
            
            
        </script> 
       
    </head>
    <body>
       
    </body>
</html>
